#ifndef INGENIC_LINPHONE_H
#define INGENIC_LINPHONE_H

#include <stdbool.h>
#include <time.h>

#ifdef __cplusplus
extern "C"
{
#endif

    /**
     * 可视通话核心库
     * - liblinphone.so
     *      - 分为室内机、室外机和双向机三种模式
     *      - 可以调用 LinphoneGetMode 查看模式
     *      - 模式由编译阶段决定
     *
     * - 通话模型
     *      - LinphoneInit      // 必须首先调用
     *      - 机体A
     *          - LinphoneCall      // 可以多次呼叫
     *          - LinphoneTerminate // 终止通话
     *      - 机体B
     *          - LinphoneInit
     *          - callback ...      // 响应回调
     *          - LinphoneAnswer    // 接听通话
     *      - LinphoneExit      // 释放可视通话库，需再次初始化
     *
     *
     * */

#include "linphone_code.h"

    void LinphoneInit(void);
    // 释放可视通话库，需再次初始化
    void LinphoneExit(void);

    // 呼叫
    void LinphoneCall(char *ip, bool video, bool earlyMedia);
    // 接听通话
    // 回调返回 id，或者使用 0 代表 id
    void LinphoneAnswer(int id);
    // 结束通话
    void LinphoneTerminate(int id);

    // 拍照
    void LinphoneSnapshot(char *filepath);

    // Audio Volume
    // - Voice Level, 0-100, Speaker
    // - Mic Level, 0-100, Microphone
    // - Ring Level, 0-100, Ringtone
    int LinphoneGetVoiceLevel(void);
    void LinphoneSetVoiceLevel(int level);
    int LinphoneGetMicLevel(void);
    void LinphoneSetMicLevel(int level);
    int LinphoneGetRingLevel(void);
    void LinphoneSetRingLevel(int level);

    // 判断网络状态
    bool LinphoneNetConnected(char *ip);

    // Callback Functions
    /**
     * state change by callback:
     *  - o -> incoming -> received() -> connected -> end
     */

    /**
     * Callback to notify a call is incoming.
     *
     * @param username the user name of target.
     * @param addr the IP address of target.
     * @param id the call ID.
     * @param video the call includes video stream or not.
     */
    extern void (*linphonec_call_imcoming_received_notify_callback)(char *username, char *addr, int id, int video);

    /**
     * Callback to notify a call is connected.
     *
     * @param addr the IP address of target.
     * @param id the call ID.
     */
    extern void (*linphonec_call_connected_notify_callback)(char *addr, int id);

    /**
     * Callback to notify a call is ended.
     *
     * @param addr the IP address of target.
     * @param id the call ID.
     */
    extern void (*linphonec_call_end_notify_callback)(char *addr, int id);

    /**
     * Callback to notify a call is error.
     *
     * @param addr the IP address of target.
     * @param id the call ID.
     * @param code the SIP error code.
     */
    extern void (*linphonec_call_error_notify_callback)(char *addr, int id, int code);

    /**
     * Callback to notify configuration file is saved. This is used to gave application change to update CRC data.
     *
     * we have one configuration file: linphonerc
     * save the audio volume level
     *
     * @param filename the file name of configuration.
     */
    extern void (*lp_config_sync_notify_callback)(char *filename);

    /**
     * Callback to notify a new log is created. This is used to sync time with snapshot.
     *
     * @param start_time the create time of log.
     */
    extern void (*linphonec_new_log_notify_callback)(time_t start_time);

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* INGENIC_LINPHONE_H */
